package com.microbroadcast.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.microbroadcast.resource.UserBasic;

public class UserBasicPersistence {

	public static UserBasic getUserBasic(long userID) {
		UserBasic result = null;
		try {
			Connection c = DBHelper.getConnection();
			String sql = "select * from userbasic where UserID = ?";
			PreparedStatement ps = c.prepareStatement(sql);
			ps.setLong(1, userID);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				String name = rs.getString("Name");
				long photoID = rs.getLong("HeadPhoto");
				byte[] headPic = PhotoPersistence.getPhoto(photoID);
				result = new UserBasic(userID, name, headPic);
			}
			rs.close();
			ps.close();
			c.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return result;
	}

}
